package
{
	
	
	import browser.SingleView;
	import browser.list;
	
	import caurina.transitions.Tweener;
	
	import datas.GlobalDatas;
	
	import events.GlobalEvents;
	
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;

	
	public class snapsMobile extends Sprite
	{
		private var listview:list;
		private var singleview:SingleView;
		
		public function snapsMobile()
		{
			super();
			
			// support autoOrients
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.addEventListener(Event.RESIZE, onResize);
			init();
		}
		
		private function addEvents():void
		{
			GlobalEvents.dispatcher.addEventListener(GlobalEvents.VIEW_SINGLE, onSingleView);
			GlobalEvents.dispatcher.addEventListener(GlobalEvents.VIEW_LIST, onListView);
		}
		
		private function init():void
		{
			addEvents();
			GlobalDatas.stagewidth = stage.stageWidth;
			listview = new list();
			listview.x = 10;
			listview.y = 10;
			addChild(listview);
		}
		
		private function onResize(e:Event):void
		{
			trace("resized", stage.stageWidth);
			GlobalDatas.stagewidth = stage.stageWidth;
			GlobalDatas.stageheight = stage.stageHeight;
			GlobalEvents.dispatcher.dispatchEvent(new Event(GlobalEvents.STAGE_RESIZED));
		}
		
		private function onSingleView(e:Event):void
		{
			trace("onSingleView", GlobalDatas.currentPhoto);
			gotoSingleView();
		}
		
		private function gotoSingleView():void
		{
			trace("gotoSingleView");
			singleview = new SingleView;
			singleview.load();
			addChild(singleview);
			GlobalEvents.dispatcher.dispatchEvent(new Event(GlobalEvents.VIEW_SINGLE_LOAD));
		}
		
		private function onListView(e:Event):void
		{
			trace("onListView", GlobalDatas.currentPhoto);
			removeChild(singleview);
			singleview = null;
			GlobalDatas.currentPhoto = null;
		}
		
		
	}
}